<?php
include_once 'i_payment_driver.php';
abstract class a_base_payment_driver extends a_base_model implements i_payment_driver{

    protected $order_object;
    protected $currency;
    protected $description;
    protected $driver_id;
    protected $error_msg;

    public function __construct(stdClass $driver_data_row){
        parent::__construct(FALSE);             
        $this->currency     = $driver_data_row->currency;
        $this->description  = $driver_data_row->description;
        $this->driver_id    = $driver_data_row->driver_id;        
    }

    public function  get_driver_id() {
        return $this->driver_id;
    }
    public function get_description(){
        return $this->description;
    }
    protected function mark_order_as_paid(){
        $this->order_object->mark_as_paid($this->get_driver_id());
    }

    protected function _post($field_name){
        return get_instance()->input->post($field_name);
    }
    
    public function process(order_m_order $obj){
        $this->order_object = $obj;
        $return = $this->validate_payment();
        if($return!==NULL){
            $payment_manager = class_loader::new_obj("payment_manager");
            $payment_manager->save_payment_info($this->get_order_obj()->id,$this->get_driver_id(), $return,xss_clean(get_instance()->input->post(module_u_checkout_payment::PAYMENT_DRIVER_USER_NOTE)));
            unset ($payment_manager);
            $this->write_transaction();
            $this->mark_order_as_paid();
            event_dispatcher::i()->fire(module_u_order::EVENT_ORDER_PAYMENT_SUCCESS,$this->order_object);
            return TRUE;
        }else{
            return FALSE;
        }
    }
    public function get_error_message() {
        return $this->error_msg;
    }
    public function get_order_obj(){
        return $this->order_object;
    }

}
?>